//
//  SubRipItem.m
//  TextTracks
//
//  Created by Sebas on 06/11/07.
//  Copyright 2007 Sebas Corp. All rights reserved.
//

#import "SubRipItem.h"


@implementation SubRipItem

@synthesize subtitleNumber;
@synthesize startTime;
@synthesize endTime;
@synthesize textOfSubtitle;

-(id)initWithString:(NSString *)aString
{
	
	if(self = [super init])
	{
		NSArray* lines = [aString componentsSeparatedByString:@"\r\n"];
		
		if([lines count] >= 3)
		{
			self.subtitleNumber = [lines objectAtIndex:0];
			
			NSMutableString* tmpTime;
			
			tmpTime = [NSMutableString stringWithString:[lines objectAtIndex:1]];
			
			NSArray * timeArray = [tmpTime componentsSeparatedByString:@" --> "];
			self.startTime = [timeArray objectAtIndex:0];
			
			self.endTime = [timeArray objectAtIndex:1];
			
			int i = 2;
			NSMutableString * tmpText = [[NSMutableString alloc] init];
			
			for(i;i < [lines count];i++)
			{
				//NSLog(@"%@",[lines objectAtIndex:i]);
				[tmpText appendString:[NSString stringWithFormat:@"%@\r\n",[lines objectAtIndex:i]]];
				
			}
			self.textOfSubtitle = tmpText;
		}	
		
	}
	return self;
}

-(id)init
{
	return [self initWithString:@""];
}

@end
